package com.ssy.lingxi.report.controller;

import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.report.model.vo.request.UpdateDataLayoutVO;
import com.ssy.lingxi.report.model.vo.response.*;
import com.ssy.lingxi.report.service.IDataLayoutService;
import com.ssy.lingxi.report.service.IMemberHomeService;
import com.ssy.lingxi.report.service.IMemberReportService;
import com.ssy.lingxi.report.service.IOrderReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * @menu 首页能力-首页
 * @author 伍将
 * @version 2.0.0
 * @date 2020/11/17
 */
@RestController
@RequestMapping("/report/member/home")
public class MemberHomeController extends BaseController {

    @Autowired
    private IMemberHomeService memberHomeService;

    @Autowired
    private IDataLayoutService dataLayoutService;

    @Autowired
    private IOrderReportService orderReportService;

    @Autowired
    private IMemberReportService memberReportService;
    /**
     * 会员中心
     * @author ds
     * @date 2020/5/8
     **/
    @RequestMapping(value = "/getMemberTally", method = RequestMethod.GET)
    Wrapper<MemberTallyReportVO> getMember(HttpServletRequest httpRequest) {
        return memberHomeService.getMemberReport(getSysUser(httpRequest));
    }

    /**
     * 订单中心
     * @author ds
     * @date 2020/5/18
     **/
    @RequestMapping(value = "/getOrderTally", method = RequestMethod.GET)
    Wrapper<OrderTallyReportVO> getOrder(HttpServletRequest httpRequest) {
        return memberHomeService.getOrderReport(getSysUser(httpRequest));
    }

    /**
     * 资金账户管理中心
     * @author 伍将
     * @date 2020/11/17
     **/
    @RequestMapping(value = "/getAccountTally", method = RequestMethod.GET)
    Wrapper<AccountTallyReportVO> getAccount(HttpServletRequest httpRequest) {
        return memberHomeService.getAccount(getSysUser(httpRequest));
    }

    /**
     * 商品中心
     * @author 伍将
     * @date 2020/11/17
     **/
    @RequestMapping(value = "/getCommodityTally", method = RequestMethod.GET)
    Wrapper<List<TallyReportItemVO>> getCommodityTallyReport(HttpServletRequest httpRequest) {
        return memberHomeService.getCommodityReport(getSysUser(httpRequest));
    }

    /**
     * 交易中心
     * @author 伍将
     * @date 2020/11/17
     **/
    @RequestMapping(value = "/getTradeTally", method = RequestMethod.GET)
    Wrapper<TradeTallyReportVO> getTradeReport(HttpServletRequest httpRequest) {
        return memberHomeService.getTradeReport(getSysUser(httpRequest));
    }

    /**
     * 物流中心
     * @author 伍将
     * @date 2020/11/18
     **/
    @RequestMapping(value = "/getLogisticsTally", method = RequestMethod.GET)
    Wrapper<LogisticsTallyReportVO> getLogisticsReport(HttpServletRequest httpRequest) {
        return memberHomeService.getLogisticsReport(getSysUser(httpRequest));
    }

    /**
     * 加工中心
     * @author 伍将
     * @date 2020/11/18
     **/
    @RequestMapping(value = "/getEnhanceTally", method = RequestMethod.GET)
    Wrapper<EnhanceTallyReportVO> getEnhanceTally(HttpServletRequest httpRequest) {
        return memberHomeService.getEnhanceReport(getSysUser(httpRequest));
    }

    /**
     * 结算中心
     * @author 伍将
     * @date 2020/11/19
     **/
    @RequestMapping(value = "/getSettleAccountTally", method = RequestMethod.GET)
    Wrapper<SettleAccountTallyReportVO> getSettleAccountReport(HttpServletRequest httpRequest) {
        return memberHomeService.getSettleAccountReport(getSysUser(httpRequest));
    }

    /**
     * 售后中心
     * @author 伍将
     * @date 2020/11/20
     **/
    @RequestMapping(value = "/getAfterSaleTally", method = RequestMethod.GET)
    Wrapper<AfterSaleTallyReportVO> getAfterSaleReport(HttpServletRequest httpRequest) {
        return memberHomeService.getAfterSaleReport(getSysUser(httpRequest));
    }
    /**
     * 合同中心
     * @author ds
     * @date 2020/5/11
     **/
    @RequestMapping(value = "/getContractTally", method = RequestMethod.GET)
    Wrapper<ContractTallyReportVO> getContractReport(HttpServletRequest httpRequest) {
        return memberHomeService.getContractReport(getSysUser(httpRequest));
    }

    /**
     * 采购中心
     * @author ds
     * @date 2020/5/14
     **/
    @RequestMapping(value = "/getPurchaseTally", method = RequestMethod.GET)
    Wrapper<PurchaseTallyReportVO> getPurchaseReport(HttpServletRequest httpRequest) {
        return memberHomeService.getPurchaseReport(getSysUser(httpRequest));
    }

    /**
     * 获取数据布局
     * @author 伍将
     * @date 2020/11/19
     **/
    @RequestMapping(value = "/getDataLayout", method = RequestMethod.GET)
    Wrapper<List<DataLayoutVO>> getDataLayout(HttpServletRequest httpRequest) {
        return dataLayoutService.getDetail(getSysUser(httpRequest));
    }

    /**
     * 更新数据布局
     * @param httpRequest 请求参数
     * @param layoutVOS 数据布局
     * @return 更新结果
     */
    @RequestMapping("/updateDataLayout")
    Wrapper<Void> updateDataLayout(HttpServletRequest httpRequest, @RequestBody @Valid List<UpdateDataLayoutVO> layoutVOS) {
        return dataLayoutService.update(getSysUser(httpRequest), layoutVOS);
    }

    /***********************************SRM首页相关接口*******************************/

    /***
     * 获取订单统计[销售订单统计]
     * @author 伍将
     * @date 2020/11/10
     **/
    @RequestMapping(value = "/getOrderList", method = RequestMethod.GET)
    Wrapper<OrderStatisticsVO> getOrderList(HttpServletRequest httpRequest) {
        return orderReportService.getOrderList(getSysUser(httpRequest));
    }

    /***
     * 获取会员统计
     * @author 伍将
     * @date 2020/11/10
     **/
    @RequestMapping(value = "/getMemberRegisterList", method = RequestMethod.GET)
    Wrapper<MemberRegisterStatisticsVO> getMemberRegisterList(HttpServletRequest httpRequest) {
        return memberReportService.getMemberRegisterListByMember(getSysUser(httpRequest));
    }
}
